from src.handler.gui import GuiHandler
from src.handler.event import EventHandler
from src.handler.sprite import SpriteHandler
from src.helper.path import PathHelper
from src.config.events import *
from mods.interfaces.player import PlayerGui

def init(client):
    print("interfaces initialised")
    
    GuiHandler.register("player", PlayerGui)    
    
    EventHandler.subscripe(SPRITEHANDLER_REGISTRY, SpriteRegistryHandler())
    EventHandler.subscripe(WINDOW_UPDATE, InterfaceHandler(client))
    EventHandler.subscripe(WINDOW_UPDATE, StandardGuiHandler())
    
    
    
class InterfaceHandler:
    
    def __init__(self, client):
        self.client = client
    
    def handle(self, event):
        for drawing in GuiHandler.drawings:
            gui = GuiHandler.get(drawing[0], self.client)
            if gui is not None:
                gui.render(drawing[1])
        GuiHandler.drawings = []
        
class StandardGuiHandler:
    
    def handle(self, event):
        GuiHandler.draw("player")
                
class SpriteRegistryHandler:
    
    def handle(self, event):
        SpriteHandler.register("gui_player", PathHelper.getPath('resources','gui','player.png'))